package com.lyf.scm.plan.domain.service.impl;

import com.lyf.scm.common.util.NoUtil;
import com.lyf.scm.plan.api.dto.SalesPlanPermissionsDTO;
import com.lyf.scm.plan.domain.repository.SalesPlanPermissionsRespository;
import com.lyf.scm.plan.domain.service.SalesPlanPermissionsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限service实现类
 *
 * @author Martin
 * @date 2020-10-31 12:15
 */
@Service
public class SalesPlanPermissionsServiceImpl implements SalesPlanPermissionsService {

    @Resource
    private SalesPlanPermissionsRespository salesPlanPermissionsRespository;

    @Override
    public List<SalesPlanPermissionsDTO> listByUserId(Long userId) {
        return salesPlanPermissionsRespository.listByUserId(userId);
    }

    @Override
    public int batchSave(List<SalesPlanPermissionsDTO> list) {
        if (list == null || list.size() == 0) {
            return 0;
        }
        list.forEach(dto -> dto.setPermissionsId(NoUtil.getRandomNo()));
        return salesPlanPermissionsRespository.batchSave(list);
    }

    @Override
    public boolean updateById(SalesPlanPermissionsDTO salesPlanPermissionsDTO) {
        int n = salesPlanPermissionsRespository.updateById(salesPlanPermissionsDTO);
        return n == 1 ? true : false;
    }
}
